﻿using System;
using System.Collections.Generic;
using System.Text;

namespace ASmile.Event
{
    public class TriggerResult
    {
        public TriggerResult() { }
        /// <summary>
        /// 指定错误消息，并返回 -2 code
        /// </summary>
        public TriggerResult(string msg) : this(-2, false, msg)
        { }
        public TriggerResult(int code, string msg = null) : this(code, false, msg)
        { }
        /// <summary>
        /// 返回成功，并指定是否跳出订阅列表循环
        /// </summary>
        public TriggerResult(bool isBreak, object tag = null) : this(0, isBreak, "OK")
        {
            Tag = tag;
        }

        public TriggerResult(int code, bool isBreak, string msg = null)
        {
            Code = code;
            Msg = msg;
            IsBreak = isBreak;
        }

        /// <summary>
        /// 是否执行成功
        /// </summary>
        public bool Success { get { return Code == 0; } }
        /// <summary>
        /// 返回 0 为成功
        /// </summary>
        public int Code { set; get; }
        /// <summary>
        /// 失败后是否返回
        /// </summary>
        public bool IsBreak { set; get; }
        /// <summary>
        /// 成功或失败的消息
        /// </summary>
        public string Msg { set; get; }
        /// <summary>
        /// 附加扩展数据
        /// </summary>
        public object Tag { set; get; }
        /// <summary>
        /// 下一个订阅执行的结果
        /// </summary>
        public TriggerResult LastResult { set; get; }
        /// <summary>
        /// 订阅对象
        /// </summary>
        public IEventSubscribe Subscribe { get; internal set; }
        /// <summary>
        /// 结果值
        /// </summary>
        public DictExtend Values { get; } = new DictExtend();
    }
}
